package com.xungou.receiver.controller;

import com.xungou.city.pojo.City;
import com.xungou.receiver.pojo.Receiver;
import com.xungou.receiver.service.IReceiverService;
import com.xungou.user.pojo.User;
import com.xungou.utils.UserUtil;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/receiver")
public class ReceiverController {
    @Resource
    private IReceiverService receiverService;

    @RequestMapping("/add")
    @ResponseBody
    public Map<String, Object> add(Receiver receiver, @RequestParam Map<String, String> params) {
        receiver.setUser(UserUtil.getCurrentUser().getId());
        int flag = receiverService.insert(receiver);
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("flag",flag);
        return result;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Map<String, Object> delete(Receiver receiver) {
        int flag = receiverService.deleteByPrimaryKey(receiver.getId());
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("flag",flag);
        return result;
    }

    @RequestMapping("/list")
    @ResponseBody
    public List<Receiver> list(@RequestParam Map<String, Object> params){
        List<Receiver> result = receiverService.list(params);
        return result;
    }

}